/**
 * 
 */
package guest;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author andersonb
 * 
 */
@Controller
public class GuestController {

	@Autowired
	private GuestDAO guestDao;

	@RequestMapping(value = "/guest")
	public ModelAndView guestbook(final HttpServletRequest request) {
		// Handle a new guest (if any):
		String name = request.getParameter("name");
		if (name != null) {
			guestDao.persist(new Guest(name));
		}

		// Prepare the result view (guest.jsp):
		return new ModelAndView("guest.jsp", "guestDao", guestDao);
	}
}
